package com.mzj.saas.mservice.announcement.controller;

import com.mzj.saas.commons.ResultBean;
import com.mzj.saas.mservice.announcement.service.AnnouncementAppService;
import com.mzj.saas.mservice.announcement.vo.*;
import com.mzj.saas.mservice.backlog.vo.AnnouncementApiData;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * app公告接口
 */
@Controller
@RequestMapping("/announcementApp")
@Api(tags = "小程序消息公告接口")
public class AnnouncementAppController {

    @Autowired
    private AnnouncementAppService announcementAppService;

    /**
     * 查询定位城市小区
     *
     * @param cityName
     * @return
     */
    @GetMapping("/findCommunity")
    @ResponseBody
    @ApiOperation("查询定位城市小区集合")
    public ResultBean<List<Map<String, Object>>> findCommunity(@RequestParam(value = "cityName")
                                                               @ApiParam(name = "cityName",value = "城市名") String cityName) {
        return announcementAppService.findCommunity(cityName);
    }

    /**
     * 公共公告列表
     *
     * @param accessToken
     * @param communityId
     * @return
     */
    @GetMapping("/publicAnnouncementList")
    @ResponseBody
    @ApiOperation("公共公告列表")
    public ResultBean<List<PublicAnnouncementListVO>> publicAnnouncementList(@RequestHeader String accessToken,
                                                                             @RequestParam(value = "communityId")
                                                                                    @ApiParam(name = "communityId",value = "小区id") String communityId) {
        return announcementAppService.publicAnnouncementList(accessToken, communityId);
    }

    /**
     * 公告列表
     *
     * @param accessToken
     * @param viewStatus 阅读状态：0全部 1已读 2未读
     * @param type
     * @param communityId
     * @param pageNumber
     * @param pageSize
     * @return
     */
    @GetMapping("/announcementList")
    @ResponseBody
    @ApiOperation("消息公告列表")
    public ResultBean<AnnouncementApiData<AnnouncementListVO>> announcementList(@RequestHeader String accessToken,
                                                                                @RequestParam(value = "viewStatus")
                                                                 @ApiParam(name = "viewStatus",value = "阅读状态：0全部 1已读 2未读") Integer viewStatus,
                                                                                @RequestParam(value = "type",required = false)
                                                                 @ApiParam(name = "type",value = "公告类型：1企业公告 2社区公告 3小区公告 4平台广告") Integer type,
                                                                                @RequestParam(value = "communityId")
                                                                 @ApiParam(name = "communityId",value = "小区id") String communityId,
                                                                                @RequestParam(defaultValue = "0")
                                                                 @ApiParam(name = "pageNumber",value = "当前页") Integer pageNumber,
                                                                                @RequestParam(defaultValue = "5")
                                                                 @ApiParam(name = "pageSize",value = "每页条数") Integer pageSize) {
        return announcementAppService.announcementList(accessToken, viewStatus, type, communityId, pageNumber, pageSize);
    }

    /**
     * 公告详情
     *
     * @param accessToken
     * @param id
     * @return
     */
    @GetMapping("/findAnnouncement")
    @ResponseBody
    @ApiOperation("公告详情与消息状态更改")
    public ResultBean<FindAnnouncementVO> findAnnouncement(@RequestHeader String accessToken, @RequestParam(value = "id")
           @ApiParam(name = "id",value = "公告id") Long id) {
        return announcementAppService.findAnnouncement(accessToken, id);
    }

    /**
     * 用户删除公告信息
     *
     * @param accessToken
     * @param idList
     * @return
     */
    @DeleteMapping("/deleteAnnouncement")
    @ResponseBody
    @ApiOperation("用户删除公告信息")
    public ResultBean<Object> deleteAnnouncement(@RequestHeader String accessToken, @RequestBody
    @ApiParam(name = "idList",value = "公告idList") List<Long> idList) {
        return announcementAppService.deleteAnnouncement(accessToken, idList);
    }
    /**
     * 消息全部已读
     *
     * @param accessToken
     * @return
     */
    @GetMapping("/allRead")
    @ResponseBody
    @ApiOperation("消息全部已读")
    public ResultBean<Object> allRead(@RequestHeader String accessToken,
                                      @RequestParam(value = "communityId")
                                      @ApiParam(name = "communityId",value = "小区id") String communityId,
                                      @RequestParam(value = "viewStatus")
                                      @ApiParam(name = "viewStatus",value = "阅读状态：0未读,1已读") Integer viewStatus) {
        return announcementAppService.allRead(accessToken,communityId,viewStatus);
    }
    /**
     * 查看社区公租房公示
     *
     * @param accessToken
     * @param id
     * @return
     */
    @GetMapping("/findHousePublicity")
    @ResponseBody
    public ResultBean<HousePublicityData<HousePublicityVO>> findHousePublicity(@RequestHeader String accessToken,
                                                                               @RequestParam(value = "id") Long id) {
        return announcementAppService.findHousePublicity(accessToken, id);
    }

    /**
     * 点赞
     *
     * @param accessToken
     * @param id
     * @return
     */
    @GetMapping("/thumb")
    @ResponseBody
    public ResultBean<Object> thumb(@RequestHeader String accessToken,
                                    @RequestParam(value = "id") Long id) {
        return announcementAppService.thumb(accessToken, id);
    }


}
